package com.v5.mr.avgvalue;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * 平均值
 *
 */
public class AvgValueMain {

	public static void main(String[] args) throws Exception {
		// 创建一个job = mapper + reducer
		Job job = Job.getInstance(new Configuration());
		// 指定job的入口
		job.setJarByClass(AvgValueMain.class);

		// 指定任务的mapper和输出数据类型
		job.setMapperClass(AvgValueMapper.class);
		job.setMapOutputKeyClass(Text.class); // 指定k2的类型
		job.setMapOutputValueClass(LongWritable.class);// 指定v2的数据类型

		// 设置任务的Combiner
		job.setCombinerClass(AvgValueReducer.class);

		// 指定任务的reducer和输出数据类型
		job.setReducerClass(AvgValueReducer.class);
		job.setOutputKeyClass(Text.class);// 指定k4的类型
		job.setOutputValueClass(DoubleWritable.class);// 指定v4的类型

		// 指定输入的路径和输出的路径
		FileInputFormat.setInputPaths(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));

		// 执行任务
		job.waitForCompletion(true);
	}

}
